package main
import ("fmt"
	"math/cmplx"
	"runtime"
	"time"
	"math"
//	"unsafe"
)
func adder()func(int)int{
	sum := 0
	return func(x int)int{
		sum +=x
		return sum
	}
}
func fibonacci() func()int{
	a,b := 0,1
	return func()int{
		a,b=b,a+b
		return a
	}
}

func sqrt(x float64)float64{
	z := float64(3)
	for i  :=0;i<10;i++{
		z=z-((z*z -x)/2 *z)
	}
	return z
}
const (
	Pi=3.14
)
func compute(fn func (float64,float64)float64)float64{
	return fn(3,4)
}
func pow(x,n,lim float64)float64{
	if v:=math.Pow(x,n);v<lim{
		return v
	}else{
		fmt.Printf("%g >=%g\n",v,lim)
	}
	return lim
	}
	type I interface {
		M()
	}
	type T struct{
		S string
	}
	func (t *T)M(){
		fmt.Println(t.S)
	}
	type F float64
	func (f F)M(){
		fmt.Println(f)
	}
func describe(i I){
	fmt.Printf("(%v,%T)\n",i,i)
}
type Vertex1 struct{
	Lat,Lng float64
}

var m=map[string]Vertex1{
	"bell labs":Vertex1{
		50.322,-73.32,
	},
	"google":Vertex1{
		-32.4,-122.04,
	},

}
func split(sum int)(x,y int){
	x=sum*4/8
	y=sum -x
	return 
}
func Sqrt1(x float64)float64{
	const E =0.000000001
	z :=float64(1)
	k :=float64(0)
	i :=0
	for ; ; z=z-(z*z-x)/(z+z){
		if z-k<=E && z-k >=-E{
		fmt.Println(i)
		return z
	}
	k=z
	fmt.Println(z)
	i++
}
}
const (
	Big =1<<100
	Small=Big >>99
)
func needInt(x int)int{
	return x*10+1
}
func needFloat(x float64)float64{
	return x*0.1
}
func hello(){
	time.Sleep(50*time.Second)
	fmt.Println("======test======")
}
func main(){
	for i :=0;i<1000000;i++{
		fmt.Println("======i======:",i)
		go hello()
		fmt.Println("current process:",runtime.NumGoroutine())
	}
	fmt.Println("main funciton")
}
	/*
	fmt.Println(needInt(Small))
	fmt.Println(needFloat(Small))
	fmt.Println(needFloat(Big))
	*/
	/*
	i,j :=42,2701
	p :=&i
	fmt.Println(*p)
	*p=21
	fmt.Println(i,*p)
	p=&j
	*p=*p/37
	fmt.Println(j,p,*p)
	*/
	/*
	pow :=make([]int ,10)
	for i :=range pow{
		pow[i] =1 <<uint(i)
	}
	for _,value :=range pow{
		fmt.Printf("%d\n",value)
	}
	*/
	/*
	/*
	q:=[]int{2,3,4,5}
	fmt.Println(q)
	r :=[]bool{true,false,true,true}
	fmt.Println(r)
	s :=[]struct{
		i int
		b bool
	}{
		{2,true},
		{3,false},
	}
	fmt.Println(s)
	*/

	//var a,b int;
	//a,b=split(20)
//	fmt.Println(split(20))
/*
fmt.Println(Sqrt1(3))
fmt.Println(math.Sqrt(3))
//	fmt.Println(m)
/*
m=make(map[string]Vertex1)

m["bell labs"]=Vertex1{
	30,20,}
	fmt.Println(m["bell labs"])
	*/
	/*
	f :=MyFloat(-math.Sqrt2)
	fmt.Println(f.Abs())
*/
//}

/*	hypot :=func(x,y float64)float64{
		return math.Sqrt(x*x +y*y)
	}
	fmt.Println(hypot(5,12))
	fmt.Println(compute(hypot))
	fmt.Println(math.Pow(3,4))
	*/
/*	fmt.Println(
		pow(3,2,10),

		pow(3,3,20),
		*/
		/*
	var i I
	i=&T{"hello"}
	describe(i)
	i.M()
	i=F(math.Pi)
	describe(i)
	i.M()

	*/
	/*
	var a Abser
	f := MyFloat(-math.Sqrt2)
	v := Vertex{6,8}
	a = f
	a =&v
	a=v
	fmt.Println(a.Abs())

}
*/
type Abser interface{
	Abs() float64
}
type MyFloat float64
func (f MyFloat)Abs() float64{
	if f<0{
		return float64(-f)
	}
	return float64(f)
}
type Vertex struct{
	X,Y float64
}
func (v Vertex) Abs() float64{
	return math.Sqrt(v.X * v.X +v.Y*v.Y)
}
/*	pos,neg :=adder(),adder()
	for i:=0;i<10;i++{
		fmt.Println(pos(i),neg(-2*i))
	}
	*/
	/*
	f :=fibonacci()
	for i:=0;i<10;i++{
		fmt.Println(f())
	}

	*/
	/*


	const (
		world="shijie"
	)
	fmt.Println("Hello",world)
	fmt.Println("Happy",Pi,"Day")
	const Truth=true
	fmt.Println("Go rules?",Truth)
	*/
	/*
	fmt.Println("counting")
	for i :=0;i<10;i++{
		defer fmt.Println("world")
//		fmt.Println("world")
		fmt.Println(i)
//		fmt.Print("hello")
	}
	fmt.Println("done")


	*/
	/*
	defer fmt.Println("world")
	fmt.Println("hello")
	*/
	/*
	x:=float64(2)
	fmt.Println(x,sqrt(x),math.Sqrt(x))
	*/
	/*
	var s []int
	printSlice(s)
	s=append(s,0)
	printSlice(s)
	s=append(s,1,2)
	printSlice(s)
	var a [2]string
	a[0]="hello"
	a[1]="world"
	fmt.Println(a[0],a[1],a)
	primes := [2]int{1,2}
	fmt.Println(primes)
	*/
/*
const (f ="%T(%v)\n")
fmt.Printf(f,ToBe,ToBe)
fmt.Printf(f,MaxInt,MaxInt)
fmt.Printf(f,Max32Int,Max32Int)
fmt.Printf(f,z,z)
*/
/*
const ( LENGTH int=10
WIDTH int=5
)
var area int
const a,b,c=1,false,"str"
area=LENGTH*WIDTH
fmt.Printf("area is:%d",area)
println()
println(a,b,c)
*/
//println(a,b)


//}
const (
	a="abc"
	b=len(a)
//	c=
)
var (
	ToBe bool
	MaxInt uint64 =1<<64 -1
	Max32Int uint32 = 1<<32 -1
	z complex128= cmplx.Sqrt(-5 +12i)
)
func printSlice(s []int){
	fmt.Printf("len=%d cap=%d %v\n",len(s),cap(s),s)
}
